﻿/***********************************************************************
 * <copyright file="GlobalVariable.cs" company="BUCA JSC">
 * -->    Copyright (C) statement. All right reserved
 * </copyright>
 * 
 * Created:   LinhMC
 * Email:    linhmc@buca.vn
 * Website:
 * Create Date: Wednesday, March 05, 2014
 * Usage: 
 * 
 * RevisionHistory: 
 * Date         Author               Description 
 * 
 * ************************************************************************/

using System;
using System.Linq;
using System.Collections.Generic;
using System.Globalization;
using WindowsForms.AOnline.Model.BusinessObjects.Dictionary;
using WindowsForms.AOnline.Presenter.Dictionary.DbOption;
using WindowsForms.AOnline.Model.BusinessObjects.Report;
using WindowsForms.AOnline.View.Dictionary;

namespace WindowsForms.AOnline.Session
{
    public class GlobalVariable : IDBOptionsView
    {

        /// <summary>
        /// The _DB options presenter
        /// </summary>
        private readonly DbOptionsPresenter _dbOptionsPresenter;

        #region Options

        /// <summary>
        /// Gets or sets a value indicating whether [is post to parent account].
        /// </summary>
        /// <value>
        /// <c>true</c> if [is post to parent account]; otherwise, <c>false</c>.
        /// </value>
        public bool IsPostToParentAccount { get; set; }

        /// <summary>
        /// Gets or sets the base of salary.
        /// </summary>
        /// <value>
        /// The base of salary.
        /// </value>
        public decimal BaseOfSalary { get; set; }

        /// <summary>
        /// Gets or sets the currency code of salary.
        /// </summary>
        /// <value>
        /// The currency code of salary.
        /// </value>
        public string CurrencyCodeOfSalary { get; set; }

        /// <summary>
        /// Gets or sets the currency accounting.
        /// </summary>
        /// <value>
        /// The currency accounting.
        /// </value>
        public string CurrencyAccounting { get; set; }

        /// <summary>
        /// Gets or sets the currency symbol.
        /// </summary>
        /// <value>
        /// The currency symbol.
        /// </value>
        public string CurrencySymbol { get; set; }

        /// <summary>
        /// Gets or sets the currency decimal separator.
        /// </summary>
        /// <value>
        /// The currency decimal separator.
        /// </value>
        public string CurrencyDecimalSeparator { get; set; }

        /// <summary>
        /// Gets or sets the currency group separator.
        /// </summary>
        /// <value>
        /// The currency group separator.
        /// </value>
        public string CurrencyGroupSeparator { get; set; }

        /// <summary>
        /// Gets or sets the currency decimal digits.
        /// </summary>
        /// <value>
        /// The currency decimal digits.
        /// </value>
        public string CurrencyDecimalDigits { get; set; }

        /// <summary>
        /// Gets or sets the currency positive pattern.
        /// </summary>
        /// <value>
        /// The currency positive pattern.
        /// </value>
        public int CurrencyPositivePattern { get; set; }

        /// <summary>
        /// Gets or sets the currency negative pattern.
        /// </summary>
        /// <value>
        /// The currency negative pattern.
        /// </value>
        public int CurrencyNegativePattern { get; set; }

        /// <summary>
        /// Gets or sets the current culture information.
        /// </summary>
        /// <value>
        /// The current culture information.
        /// </value>
        public CultureInfo CurrentCultureInfo { get; set; }

        /// <summary>
        /// Gets or sets the chapter font.
        /// </summary>
        /// <value>
        /// The chapter font.
        /// </value>
        public string ChapterFont { get; set; }

        /// <summary>
        /// Gets or sets the company address font.
        /// </summary>
        /// <value>
        /// The company address font.
        /// </value>
        public string CompanyAddressFont { get; set; }

        /// <summary>
        /// Gets or sets the company address.
        /// </summary>
        /// <value>
        /// The company address.
        /// </value>
        public string CompanyAddress { get; set; }

        /// <summary>
        /// Gets or sets the company bank account no.
        /// </summary>
        /// <value>
        /// The company bank account no.
        /// </value>
        public string CompanyBankAccountNo { get; set; }

        /// <summary>
        /// Gets or sets the company bank adrress.
        /// </summary>
        /// <value>
        /// The company bank adrress.
        /// </value>
        public string CompanyBankAdrress { get; set; }

        /// <summary>
        /// Gets or sets the name of the company bank.
        /// </summary>
        /// <value>
        /// The name of the company bank.
        /// </value>
        public string CompanyBankName { get; set; }

        /// <summary>
        /// Gets or sets the company cashier.
        /// </summary>
        /// <value>
        /// The company cashier.
        /// </value>
        public string CompanyCashier { get; set; }

        /// <summary>
        /// Gets or sets the company cashier title.
        /// </summary>
        /// <value>
        /// The company cashier title.
        /// </value>
        public string CompanyCashierTitle { get; set; }

        /// <summary>
        /// Gets or sets the company accountant.
        /// </summary>
        /// <value>
        /// The company accountant.
        /// </value>
        public string CompanyAccountant { get; set; }

        /// <summary>
        /// Gets or sets the company chief accountant title.
        /// </summary>
        /// <value>
        /// The company chief accountant title.
        /// </value>
        public string CompanyChiefAccountantTitle { get; set; }

        /// <summary>
        /// Gets or sets the company city.
        /// </summary>
        /// <value>
        /// The company city.
        /// </value>
        public string CompanyCity { get; set; }

        /// <summary>
        /// Gets or sets the company code.
        /// </summary>
        /// <value>
        /// The company code.
        /// </value>
        public string CompanyCode { get; set; }

        /// <summary>
        /// Gets or sets the company code font.
        /// </summary>
        /// <value>
        /// The company code font.
        /// </value>
        public string CompanyCodeFont { get; set; }

        /// <summary>
        /// Gets or sets the company director.
        /// </summary>
        /// <value>
        /// The company director.
        /// </value>
        public string CompanyDirector { get; set; }

        /// <summary>
        /// Gets or sets the company director title.
        /// </summary>
        /// <value>
        /// The company director title.
        /// </value>
        public string CompanyDirectorTitle { get; set; }

        /// <summary>
        /// Gets or sets the company district.
        /// </summary>
        /// <value>
        /// The company district.
        /// </value>
        public string CompanyDistrict { get; set; }

        /// <summary>
        /// Gets or sets the company email.
        /// </summary>
        /// <value>
        /// The company email.
        /// </value>
        public string CompanyEmail { get; set; }

        /// <summary>
        /// Gets or sets the company fax.
        /// </summary>
        /// <value>
        /// The company fax.
        /// </value>
        public string CompanyFax { get; set; }

        /// <summary>
        /// Gets or sets the company in charge.
        /// </summary>
        /// <value>
        /// The company in charge.
        /// </value>
        public string CompanyInCharge { get; set; }

        /// <summary>
        /// Gets or sets the company in charge font.
        /// </summary>
        /// <value>
        /// The company in charge font.
        /// </value>
        public string CompanyInChargeFont { get; set; }

        /// <summary>
        /// Gets or sets the name of the company.
        /// </summary>
        /// <value>
        /// The name of the company.
        /// </value>
        public string CompanyName { get; set; }

        /// <summary>
        /// Gets or sets the company name font.
        /// </summary>
        /// <value>
        /// The company name font.
        /// </value>
        public string CompanyNameFont { get; set; }

        /// <summary>
        /// Gets or sets the company phone.
        /// </summary>
        /// <value>
        /// The company phone.
        /// </value>
        public string CompanyPhone { get; set; }

        /// <summary>
        /// Gets or sets the company province.
        /// </summary>
        /// <value>
        /// The company province.
        /// </value>
        public string CompanyProvince { get; set; }

        /// <summary>
        /// Gets or sets the company report preparer.
        /// </summary>
        /// <value>
        /// The company report preparer.
        /// </value>
        public string CompanyReportPreparer { get; set; }

        /// <summary>
        /// Gets or sets the company report preparer title.
        /// </summary>
        /// <value>
        /// The company report preparer title.
        /// </value>
        public string CompanyReportPreparerTitle { get; set; }

        /// <summary>
        /// Gets or sets the company store keeper.
        /// </summary>
        /// <value>
        /// The company store keeper.
        /// </value>
        public string CompanyStoreKeeper { get; set; }

        /// <summary>
        /// Gets or sets the company store keeper title.
        /// </summary>
        /// <value>
        /// The company store keeper title.
        /// </value>
        public string CompanyStoreKeeperTitle { get; set; }

        /// <summary>
        /// Gets or sets the company tax code.
        /// </summary>
        /// <value>
        /// The company tax code.
        /// </value>
        public string CompanyTaxCode { get; set; }

        /// <summary>
        /// Gets or sets the company in charge sort order on report.
        /// </summary>
        /// <value>
        /// The company in charge sort order on report.
        /// </value>
        public int CompanyInChargeSortOrderOnReport { get; set; }

        /// <summary>
        /// Gets or sets the company adrress order on report.
        /// </summary>
        /// <value>
        /// The company adrress order on report.
        /// </value>
        public int CompanyAdrressOrderOnReport { get; set; }

        /// <summary>
        /// Gets or sets the company name sort order on report.
        /// </summary>
        /// <value>
        /// The company name sort order on report.
        /// </value>
        public int CompanyNameSortOrderOnReport { get; set; }

        /// <summary>
        /// Gets or sets the company code order on report.
        /// </summary>
        /// <value>
        /// The company code order on report.
        /// </value>
        public int CompanyCodeOrderOnReport { get; set; }

        /// <summary>
        /// Gets or sets the chapter order on report.
        /// </summary>
        /// <value>
        /// The chapter order on report.
        /// </value>
        public int ChapterOrderOnReport { get; set; }

        /// <summary>
        /// Gets or sets the currency unit price digits.
        /// </summary>
        /// <value>
        /// The currency unit price digits.
        /// </value>
        public int CurrencyUnitPriceDigits { get; set; }

        /// <summary>
        /// Gets or sets the exchange rate digits.
        /// </summary>
        /// <value>
        /// The exchange rate digits.
        /// </value>
        public int ExchangeRateDigits { get; set; }

        /// <summary>
        /// Gets or sets the quantity digits.
        /// </summary>
        /// <value>
        /// The quantity digits.
        /// </value>
        public int QuantityDigits { get; set; }

        /// <summary>
        /// Gets or sets the general decimal separator.
        /// </summary>
        /// <value>
        /// The general decimal separator.
        /// </value>
        public string GeneralDecimalSeparator { get; set; }

        /// <summary>
        /// Gets or sets the general group separator.
        /// </summary>
        /// <value>
        /// The general group separator.
        /// </value>
        public string GeneralGroupSeparator { get; set; }

        /// <summary>
        /// Gets or sets the display vourcher mode.
        /// </summary>
        /// <value>
        /// The display vourcher mode.
        /// </value>
        public int DisplayVourcherMode { get; set; }

        /// <summary>
        /// Gets or sets the posted date.
        /// </summary>
        /// <value>
        /// The posted date.
        /// </value>
        public string PostedDate { get; set; }

        /// <summary>
        /// Gets or sets the started date.
        /// </summary>
        /// <value>
        /// The started date.
        /// </value>
        public static string StartedDate { get; set; }

        /// <summary>
        /// Gets or sets the system date.
        /// </summary>
        /// <value>
        /// The system date.
        /// </value>
        public static string SystemDate { get; set; }

        /// <summary>
        /// Gets or sets from date.
        /// </summary>
        /// <value>
        /// From date.
        /// </value>
        public static DateTime FromDate { get; set; }

        /// <summary>
        /// Gets or sets to date.
        /// </summary>
        /// <value>
        /// To date.
        /// </value>
        public static DateTime ToDate { get; set; }

        /// <summary>
        /// Gets or sets the name of the server.
        /// </summary>
        /// <value>
        /// The name of the server.
        /// </value>
        public static string ServerName { get; set; }

        /// <summary>
        /// Gets or sets the name of the database.
        /// </summary>
        /// <value>
        /// The name of the database.
        /// </value>
        public static string DatabaseName { get; set; }

        /// <summary>
        /// Gets or sets the name of the login.
        /// </summary>
        /// <value>
        /// The name of the login.
        /// </value>
        public static string LoginName { get; set; }

        /// <summary>
        /// Gets or sets the full name.
        /// </summary>
        /// <value>
        /// The full name.
        /// </value>
        public static string FullName { get; set; }

        /// <summary>
        /// Gets or sets the connection string.
        /// </summary>
        /// <value>
        /// The connection string.
        /// </value>
        public static string ConnectionString { get; set; }

        /// <summary>
        /// The assembly path
        /// </summary>
        private static readonly string AssemblyPath = System.Reflection.Assembly.GetExecutingAssembly().Location.Substring(0, System.Reflection.Assembly.GetExecutingAssembly().Location.LastIndexOf(@"\", StringComparison.Ordinal));

        /// <summary>
        /// The path
        /// </summary>
        private static readonly string Path = AssemblyPath.Substring(0, AssemblyPath.LastIndexOf(@"\", StringComparison.Ordinal));

        /// <summary>
        /// The report path
        /// </summary>
        public string ReportPath = Path + @"\Report\";

        /// <summary>
        /// The combo path layout
        /// </summary>
        public static string ComboPathLayout = Path + @"\ComboLayout\";

        /// <summary>
        /// The template path
        /// </summary>
        public string TemplatePath = "";

        /// <summary>
        /// The bin path
        /// </summary>
        public string BinPath = "";

        /// <summary>
        /// The type path
        /// </summary>
        public string TypePath = "";

        /// <summary>
        /// The produc name
        /// </summary>
        public string ProducName = "A-BIGTIME.NET 2014";

        /// <summary>
        /// The application name
        /// </summary>
        public static string ApplicationName = "A-BIGTIME.NET 2014";

        /// <summary>
        /// Gets or sets the report list.
        /// </summary>
        /// <value>
        /// The report list.
        /// </value>
        public ReportListModel ReportList { get; set; }

        /// <summary>
        /// Gets or sets the name of the store procedure.
        /// </summary>
        /// <value>
        /// The name of the store procedure.
        /// </value>
        public string StoreProcedureName { get; set; }

        /// <summary>
        /// The currency main
        /// </summary>
        public static string CurrencyMain = "USD";

        /// <summary>
        /// The currency display string
        /// </summary>
        public static string CurrencyDisplayString = "{0:c}";

        /// <summary>
        /// The numeric display string
        /// </summary>
        public static string NumericDisplayString = "{0:n}";

        /// <summary>
        /// Gets or sets the type of the reference.
        /// </summary>
        /// <value>
        /// The type of the reference.
        /// </value>
        public int RefType { get; set; }

        /// <summary>
        /// Gets or sets the reference identifier.
        /// </summary>
        /// <value>
        /// The reference identifier.
        /// </value>
        public long RefId { get; set; }

        #endregion

        #region IDBOptionsView

        /// <summary>
        /// Gets or sets the database options.
        /// </summary>
        /// <value>
        /// The database options.
        /// </value>
        /// <exception cref="System.NotImplementedException"></exception>
        public IList<DbOptionModel> DBOptions
        {
            set
            {
                if (value == null) return;
                CompanyDirector = (from dbOption in value where dbOption.Code == "CompanyDirector" select dbOption.Value).First();
                CompanyReportPreparer = (from dbOption in value where dbOption.Code == "CompanyReportPreparer" select dbOption.Value).First();
                //CompanyReportPreparer = (from dbOption in value where dbOption.Code == "CompanyReportPreparer" select dbOption.Value).First();
                CompanyAccountant = (from dbOption in value where dbOption.Code == "CompanyAccountant" select dbOption.Value).First();
                CompanyCashier = (from dbOption in value where dbOption.Code == "CompanyCashier" select dbOption.Value).First();
                CompanyStoreKeeper = (from dbOption in value where dbOption.Code == "CompanyStoreKeeper" select dbOption.Value).First();
                StartedDate = (from dbOption in value where dbOption.Code == "StartedDate" select dbOption.Value).First();
                CompanyNameFont = (from dbOption in value where dbOption.Code == "CompanyNameFont" select dbOption.Value).First();
                CompanyAddressFont = (from dbOption in value where dbOption.Code == "CompanyAddressFont" select dbOption.Value).First();

                //number format
                CurrencySymbol = (from dbOption in value where dbOption.Code == "CurrencySymbol" select dbOption.Value).First();
                CurrencyDecimalSeparator = (from dbOption in value where dbOption.Code == "CurrencyDecimalSeparator" select dbOption.Value).First();
                CurrencyGroupSeparator = (from dbOption in value where dbOption.Code == "CurrencyGroupSeparator" select dbOption.Value).First();
                CurrencyDecimalDigits = (from dbOption in value where dbOption.Code == "CurrencyDecimalDigits" select dbOption.Value).First();

                DisplayVourcherMode = int.Parse((from dbOption in value where dbOption.Code == "DisplayVourcherMode" select dbOption.Value).First());
                PostedDate = (from dbOption in value where dbOption.Code == "PostedDate" select dbOption.Value).First();
                CurrencyCodeOfSalary = (from dbOption in value where dbOption.Code == "CurrencyCodeOfSalary" select dbOption.Value).First();
                CurrencyAccounting = (from dbOption in value where dbOption.Code == "CurrencyAccounting" select dbOption.Value).First();
                SystemDate = (from dbOption in value where dbOption.Code == "SystemDate" select dbOption.Value).First();
                BaseOfSalary = decimal.Parse((from dbOption in value where dbOption.Code == "BaseOfSalary" select dbOption.Value).First());
                IsPostToParentAccount = bool.Parse((from dbOption in value where dbOption.Code == "IsPostToParentAccount" select dbOption.Value).First());
            }
            get { throw new NotImplementedException(); }
        }

        #endregion

        /// <summary>
        /// Initializes a new instance of the <see cref="GlobalVariable"/> class.
        /// </summary>
        public GlobalVariable()
        {
            _dbOptionsPresenter = new DbOptionsPresenter(this);
            //_dbOptionsPresenter.Display();
            //GetCompanyOption();
        }

        /// <summary>
        /// Gets the number format option.
        /// </summary>
        public void GetNumberFormatOption()
        {
            //CurrencySymbol = _blOption.GetOptionValue("CurrencySymbol").ToString();
            //CurrencyDecimalSeparator = _blOption.GetOptionValue("CurrencyDecimalSeparator").ToString();
            //CurrencyGroupSeparator = _blOption.GetOptionValue("CurrencyGroupSeparator").ToString();
            //CurrencyDecimalDigits = int.Parse(_blOption.GetOptionValue("CurrencyDecimalDigits").ToString());
            //CurrencyPositivePattern = int.Parse(_blOption.GetOptionValue("CurrencyPositivePattern").ToString());
            //CurrencyNegativePattern = int.Parse(_blOption.GetOptionValue("CurrencyNegativePattern").ToString());

            CurrentCultureInfo = new CultureInfo("vi-VN")
            {
                NumberFormat =
                {
                    CurrencySymbol = CurrencySymbol,
                    CurrencyDecimalSeparator = CurrencyDecimalSeparator,
                    CurrencyGroupSeparator = CurrencyGroupSeparator,
                    CurrencyDecimalDigits = int.Parse(CurrencyDecimalDigits),
                    CurrencyPositivePattern = CurrencyPositivePattern,
                    CurrencyNegativePattern = CurrencyNegativePattern
                }
            };
        }

        /// <summary>
        /// Gets the company option.
        /// </summary>
        public void GetCompanyOption()
        {
            //CompanyAddressFont = _blOption.GetOptionValue("CompanyAddressFont").ToString();
            //CompanyAddress = _blOption.GetOptionValue("CompanyAdrress").ToString();
            //CompanyBankAccountNo = _blOption.GetOptionValue("CompanyBankAccountNo").ToString();
            //CompanyBankAdrress = _blOption.GetOptionValue("CompanyBankAdrress").ToString();
            //CompanyBankName = _blOption.GetOptionValue("CompanyBankName").ToString();
            //CompanyCashier = _blOption.GetOptionValue("CompanyCashier").ToString();
            //CompanyCashierTitle = _blOption.GetOptionValue("CompanyCashierTitle").ToString();
            //CompanyChiefAccountant = _blOption.GetOptionValue("CompanyChiefAccountant").ToString();
            //CompanyChiefAccountantTitle = _blOption.GetOptionValue("CompanyChiefAccountantTitle").ToString();
            //CompanyCity = _blOption.GetOptionValue("CompanyCity").ToString();
            //CompanyCode = _blOption.GetOptionValue("CompanyCode").ToString();
            //CompanyCodeFont = _blOption.GetOptionValue("CompanyCodeFont").ToString();
            //CompanyDirector = _blOption.GetOptionValue("CompanyDirector").ToString();
            //CompanyDirectorTitle = _blOption.GetOptionValue("CompanyDirectorTitle").ToString();
            //CompanyDistrict = _blOption.GetOptionValue("CompanyDistrict").ToString();
            //CompanyEmail = _blOption.GetOptionValue("CompanyEmail").ToString();
            //CompanyFax = _blOption.GetOptionValue("CompanyFax").ToString();
            //CompanyInCharge = _blOption.GetOptionValue("CompanyInCharge").ToString();
            //CompanyInChargeFont = _blOption.GetOptionValue("CompanyInChargeFont").ToString();
            //CompanyName = _blOption.GetOptionValue("CompanyName").ToString();
            //CompanyNameFont = _blOption.GetOptionValue("CompanyNameFont").ToString();
            //CompanyPhone = _blOption.GetOptionValue("CompanyPhone").ToString();
            //CompanyProvince = _blOption.GetOptionValue("CompanyProvince").ToString();
            //CompanyReportPreparer = _blOption.GetOptionValue("CompanyReportPreparer").ToString();
            //CompanyReportPreparerTitle = _blOption.GetOptionValue("CompanyReportPreparerTitle").ToString();
            //CompanyStoreKeeper = _blOption.GetOptionValue("CompanyStoreKeeper").ToString();
            //CompanyStoreKeeperTitle = _blOption.GetOptionValue("CompanyStoreKeeperTitle").ToString();
            //CompanyTaxCode = _blOption.GetOptionValue("CompanyTaxCode").ToString();
        }
    }
}
